<template>
	<view class="page-body" :class="[app.setCStyle()]">
		<view class=" ostatus mt0">
			<!-- 订单状态 -->
			<view v-if="orderInfo.ostatus=='待付款'" >
				<view class="smll">
					<u-icon name="/static/public/images/icon_pay.png" size="48"></u-icon>
					<text class="fs34 color-ff ml20">{{orderInfo.ostatus}}</text>
				</view>
				<view class="mt10 color-ff2">立即付款将你的宝贝带回家吧！</view>
			</view>
			<view v-else-if="orderInfo.ostatus=='付款待审核'" >
				<view class="smll">
					<u-icon name="/static/public/images/icon_pay.png" size="48"></u-icon>
					<text class="fs34 color-ff ml20">{{orderInfo.ostatus}}</text>
				</view>
				<view class="mt10 color-ff2">已提交线下支付凭证，我们将尽快审核！</view>
			</view>
			<view v-else-if="orderInfo.ostatus=='待发货' && !orderInfo.verify_code" >
				<view class="smll">
					<u-icon name="/static/public/images/icon_wait.png" size="48"></u-icon>
					<text class="fs34 color-ff ml20">{{orderInfo.ostatus}}</text>
				</view>
				<view class="mt10 color-ff2">您的商品还在打包中，请耐心等待！</view>
			</view>
			<view v-else-if="orderInfo.ostatus=='待发货' && orderInfo.verify_code" >
				<view class="smll">
					<u-icon name="/static/public/images/icon_wait.png" size="48"></u-icon>
					<text class="fs34 color-ff ml20">待核销</text>
				</view>
				<view class="mt10 color-ff2">请前往提货门店核销订单！</view>
			</view>
			<view v-else-if="orderInfo.ostatus=='已发货' && !orderInfo.verify_code" >
				<view class="smll">
					<u-icon name="/static/public/images/icon_receive.png" size="48"></u-icon>
					<text class="fs34 color-ff ml20">{{orderInfo.ostatus}}</text>
				</view>
				<view class="mt10 color-ff2">您的商品已经火速运输中，请耐心等待！</view>
			</view>
			<view v-else-if="orderInfo.ostatus=='已发货' && orderInfo.verify_code" >
				<view class="smll">
					<u-icon name="/static/public/images/icon_receive.png" size="48"></u-icon>
					<text class="fs34 color-ff ml20">待核销</text>
				</view>
				<view class="mt10 color-ff2">请前往提货门店核销订单！</view>
			</view>
			<view v-else-if="orderInfo.ostatus=='待收货'" >
				<view class="smll">
					<u-icon name="/static/public/images/icon_receive.png" size="48"></u-icon>
					<text class="fs34 color-ff ml20">{{orderInfo.ostatus}}</text>
				</view>
				<view class="mt10 color-ff2">您的商品已经火速运输中，请耐心等待！</view>
			</view>
			<view v-else-if="orderInfo.ostatus=='已取消'">
				<view class="smll">
					<u-icon name="/static/public/images/icon_wrong.png" size="48"></u-icon>
					<text class="fs34 color-ff ml20">{{orderInfo.ostatus}}</text>
				</view>
			</view>
			<view v-else-if="orderInfo.ostatus=='已取消，已退款'" >
				<view class="smll">
					<u-icon name="/static/public/images/icon_wrong.png" size="48"></u-icon>
					<text class="fs34 color-ff ml20">{{orderInfo.ostatus}}</text>
				</view>
				<view class="mt10 color-ff2">订单已取消，支付款已退回！</view>
			</view>
			<view v-else-if="orderInfo.ostatus=='已完成'">
				<view class="smll">
					<u-icon name="/static/public/images/icon_right.png" size="48"></u-icon>
					<text class="fs34 color-ff ml20">{{orderInfo.ostatus}}</text>
				</view>
			</view>
		</view>
		<!-- 物流 -->
		<view v-if="shippingLog.context" class="p20 bg-white mb20 flex" @click="app.goPage('shippingLog?order_id='+order_id)">
			<u-icon name="car" class="mr20" size="42"></u-icon>
			<view class="flex_bd">
				<view class="fs30">{{shippingLog.context}}</view>
				<view class="color-cc fs28">{{shippingLog.time}}</view>
			</view>
			<u-icon name="arrow-right" class="color-cc" size="32"></u-icon>
		</view>
		<view class="writeOff" v-if="orderInfo.verify_code && orderInfo.pay_status == 1">
			<view class="title">核销信息</view>
			<view class="grayBg">
				<view class="written" v-if="orderInfo.shipping_status == 2">
					<image :src="baseUrl+'/static/images/written.png'"></image>
				</view>
				<view class="pictrue">
					<ayQrcode ref="qrcode" :modal="modal_qr" :url="orderInfo.verify_code" @hideQrcode="hideQrcode" />
				</view>
			</view>
			<view class="gear">
				<image :src="baseUrl+'/static/images/writeOff.jpg'"></image>
			</view>
			<view class="num">{{ orderInfo.verify_code }}</view>
			<view class="rules">
				<view class="item">
					<view class="rulesTitle acea-row row-middle">
						<text class="iconfont icon-shuoming1"></text>
						使用说明
					</view>
					<view class="info">
						可将二维码出示给店员扫描或提供数字核销码
					</view>
				</view>
			</view>
		</view>
		<view v-if="orderInfo.verify_code">
			<view class="map acea-row row-between-wrapper">
				<view>下单信息</view>
			</view>
			<view class="wrapper" style="margin-top: 0;">
				<view class="item acea-row row-between">
					<view>联系人：</view>
					<view class="conter">{{ orderInfo.consignee }}</view>
				</view>
				<view class="actualPay acea-row row-between">
					<view>手机号码：</view>
					<view class="conter">{{ orderInfo.mobile }}</view>
				</view>
			</view>
			<view class="map acea-row row-between-wrapper">
				<view>门店地址</view>
			</view>
			<view>
				<view class="hx-address acea-row row-between-wrapper">
					<view class="address-box">
						<view class="name" @tap="makePhone">
							{{ orderInfo.store.store_name }}
							<text class="store_phone">{{ orderInfo.store.store_tel }}</text>
						</view>
						<view>{{ orderInfo.store.store_address }}</view>
					</view>
					<view class="icon acea-row row-middle">
						<u-icon name="phone-fill" color="#ff9900"  style="position: relative;top: 7px;" size="38" @click.stop="makePhone"></u-icon>
						<u-icon name="map-fill" style="position: relative;top: 7px;" color="#19be6b" size="38" @click.stop="showMaoLocation(orderInfo.goods)"></u-icon>
					</view>
				</view>
			</view>
		</view>

		<!-- 地址 -->
		<view class="address-content bg-white" v-if="!orderInfo.verify_code">
			<u-icon name="/static/public/images/icon_live.png" class=" mr20" size="42"></u-icon>
			<view class="cen">
				<view class="top">
					<text class="name">{{orderInfo.consignee}}</text>
					<text class="mobile">{{orderInfo.mobile}}</text>
				</view>
				<text class="address">{{orderInfo.merger_name}} {{orderInfo.address}}</text>
			</view>
		</view>
		<view class="mt20 bg-white p20">
			<!-- 商品列表 -->
			<view v-for="(item, index) in orderInfo.goodsList" :key="item.rec_id" class="flex mt20">
				<image :src="baseUrl+item.pic" style="width:140rpx;height:140rpx;"></image>
				<view class="flex_bd ml20">
					<view class="flex">
						<view class="goods_name flex_bd">{{item.goods_name}}</view>
						<view class="ml10">
							<view><text class="fs22">￥</text>{{item.sale_price}}</view>
							<view class="text-right color-99">x{{item.goods_number}}</view>
						</view>
					</view>
					<view class="flex mt10">
						<view v-if="item.sku_id > 0" class="color-cc fs26">{{item.sku_name}}</view>
						<view class="text-right flex_bd">
							<text v-if="item.goods_number - item.after_sale_num == 0" class="fs26 b-all br30 border-color base-color ptm5 plr10" @click="app.goPage('/pages/shop/aftersale/index')">查看售后</text>
							<text v-else-if="orderInfo.isAfterSale == 1" @click="app.goPage('/pages/shop/aftersale/apply?rec_id='+item.rec_id)" class="fs26 b-all br30 border-color base-color ptm5 plr10">申请售后</text>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 金额明细 -->
		<view class="yt-list mt20">
			<view class="yt-list-cell ">
				<text class="cell-tit clamp">商品金额</text>
				<text class="cell-tip money-label ff fs32 base-color">{{orderInfo.goods_amount}}</text>
			</view>

			<view v-if="orderInfo.purchase_type != 1" class="yt-list-cell">
				<text class="cell-tit clamp">运费</text>
				<text class="cell-tip money-label ff fs32 base-color">{{orderInfo.shipping_fee}}</text>
			</view>
			<view v-if="setting.sys_model_shop_bonus == 1" class="yt-list-cell">
				<text class="cell-tit clamp">优惠券</text>
				<text class="mr10">-</text><text class="cell-tip money-label ff fs32 ">{{orderInfo.use_bonus}}</text>
			</view>
			<view class="yt-list-cell ">
				<text class="cell-tit clamp">实付款</text>
				<text class="cell-tip ff fs40 color-base money-label base-color">{{orderInfo.order_amount}}</text>
			</view>
			<view class="yt-list-cell desc-cell">
				<text class="cell-tit clamp">备注</text>
				<view class="fs28">{{orderInfo.buyer_message}}</view>
			</view>
		</view>


		<view v-if="orderInfo.shipping_id > 0" class="bg-white">
			<view class="yt-list-cell">
				<text class="cell-tit clamp">快递公司</text>
				<text class="cell-tip">{{orderInfo.shipping_name}}</text>
			</view>
			<view class="yt-list-cell">
				<text class="cell-tit clamp">快递单号</text>
				<text class="cell-tip">{{orderInfo.invoice_no}}</text>
			</view>
			<view class="yt-list-cell">
				<text class="cell-tit clamp">发货时间</text>
				<text class="cell-tip">{{orderInfo._shipping_time}}</text>
			</view>
		</view>
		<!-- 金额明细 -->
		<view class="yt-list mt20">
			<view class="yt-list-cell">
				<text class="cell-tit clamp">订单编号</text>
				<text class="cell-tip">{{orderInfo.order_sn}}</text>
			</view>
			<view class="yt-list-cell">
				<text class="cell-tit clamp">创建时间</text>
				<text class="cell-tip">{{orderInfo._add_time}}</text>
			</view>

			<view v-if="orderInfo.cancel_time > 0" class="yt-list-cell">
				<text class="cell-tit clamp">取消时间</text>
				<text class="cell-tip">{{orderInfo._cancel_time}}</text>
			</view>

			<view v-if="orderInfo.pay_status != 0">
				<view class="yt-list-cell">
					<text class="cell-tit clamp">支付方式</text>
					<text class="cell-tip">{{orderInfo.pay_name}}</text>
				</view>
				<view v-if="orderInfo.pay_code == 'offline'">
					<view class="yt-list-cell">
						<text class="cell-tit clamp">上传时间</text>
						<text class="cell-tip">{{orderInfo._pay_time}}</text>
					</view>
					<view class="yt-list-cell ">
						<text class="cell-tit clamp">上传凭证</text>
					</view>
					<view class="yt-list-cell">
						<view class="offlineimg_item" v-for="(pic, index) in orderInfo.offlineimg" :key="index">
							<image :src="baseUrl+pic" @click="app.showImg(offlineimgList,index)"></image>
						</view>
					</view>
					<view v-if="orderInfo.pay_status == '11'" class="yt-list-cell ">
						<text class="cell-tit clamp">审核失败</text>
						<text class="cell-tip color-baseb">{{orderInfo.transaction_id}}</text>
					</view>
				</view>
				<view v-else>
					<view class="yt-list-cell">
						<text class="cell-tit clamp">支付时间</text>
						<text class="cell-tip">{{orderInfo._pay_time}}</text>
					</view>
					<view v-if="orderInfo.transaction_id != ''" class="yt-list-cell">
						<text class="cell-tit clamp">交易流水号</text>
						<text class="cell-tip">{{orderInfo.transaction_id}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="h150"></view>
		<view class="action-box p20">
			<button v-if="orderInfo.invoice_no" class="ml10 action-btn" @click="app.goPage('shippingLog?order_id='+order_id)">查看物流</button>
			<button v-if="orderInfo.isReview == 1" class="ml10 action-btn recom" @click="app.goPage('/pages/shop/comment/my')">立即评论</button>
			<button v-if="orderInfo.isCancel == 1" class="ml10 action-btn" @click="orderAction('cancel')">取消订单</button>
			<button v-if="orderInfo.isPay == 1" class="ml10 action-btn recom" @click="app.goPage('pay?order_id='+order_id)">立即支付</button>
			<button v-if="orderInfo.isSign == 1" class="ml10 action-btn recom" @click="orderAction('sign')">确认签收</button>
			<button class="ml10 action-btn " @click="app.goPage('/')">返回首页</button>
		</view>
	</view>
</template>

<script>
	// import zbCode from '@/components/zb-code/zb-code.vue';
	
	import ayQrcode from "@/components/ay-qrcode/ay-qrcode.vue"
	export default {
		data() {
			return {
				baseUrl: this.config.baseUrl,
				setting: {},
				order_id: 0,
				orderInfo: {},
				remark: '',
				shipping_id: 0,
				invoice_no: '',
				offlineimgList: [],
				shippingLog:[],
				//二维码参数
				codeShow: false,
				cid: '1',
				ifShow: true,
				val: '', // 要生成的二维码值
				size: 200, // 二维码大小
				unit: 'upx', // 单位
				background: '#FFF', // 背景色
				foreground: '#000', // 前景色
				pdground: '#000', // 角标色
				icon: '', // 二维码图标
				iconsize: 40, // 二维码图标大小
				lv: 3, // 二维码容错级别 ， 一般不用设置，默认就行
				onval: true, // val值变化时自动重新生成二维码
				loadMake: true, // 组件加载完成后自动生成二维码
				src: '', // 二维码生成后的图片地址或base64
				codeSrc: '',
				wd: 0,
				hg: 0,
				mpUrl: '',
				modal_qr: false,
			}
		},
		components: {
			ayQrcode
		},
		onLoad(options) {
			this.app.isLogin(this);//强制登陆
			let order_id = parseInt(options.order_id);
			if (isNaN(order_id) == true || order_id < 1) {
				this.app.showModal('订单ID传值错误.', -1);
				return false;
			}
			this.order_id = order_id;
			this.setting = uni.getStorageSync("setting");
			
		},
		onShow() {
			this.getOrderInfo();
		},
		methods: {
			kQrcode(){
				let _this = this;
				this.modal_qr = true;
				// uni.showLoading()
				setTimeout(function() {
					// uni.hideLoading()
					_this.$refs.qrcode.crtQrCode()
				}, 50)
			},
			//传入组件的方法
			hideQrcode() {
				this.modal_qr = false;
			},
			qrR(res) {
				this.codeSrc = res;
			},
			getOrderInfo() {
				let that = this;
				this.$u.post('shop/api.order/info', {
					order_id: this.order_id
				}).then(res => {
					this.orderInfo = res.data;
					this.orderInfo.offlineimg.forEach(url => {
						that.offlineimgList.push(that.config.baseUrl + url);
					})
					this.kQrcode()
					
				}).catch(res => {})
			},
			orderAction(type) {
				let that = this;
				let tip = '';
				if (type == 'cancel') {
					tip = '确认取消订单？操作后无法撤回.';
				} else if (type == 'sign') {
					tip = '确认已收到商品？操作后无法撤回.';
				}
				uni.showModal({
					title: '提示',
					content: tip,
					showCancel: true,
					success: function(res) {
						if (res.confirm) {
							that.$u.post('shop/api.order/action', {
								order_id: that.order_id,
								type: type
							}).then(res => {
								that.getOrderInfo();
							})
						}
					}
				})
			},
			//获取物流信息
			getShippingLog(){
				this.$u.post('shop/api.shipping/getLog', {
					order_id: this.order_id,
				}).then(res => {
					if (res.code == 1){
						this.shippingLog = res.data[0];
					}
				})
			},
			/**
			 * 拨打电话
			 */
			makePhone: function () {
				uni.makePhoneCall({
					phoneNumber: this.orderInfo.store.store_tel
				});
			},
			/**
			 * 打开地图
			 *
			 */
			showMaoLocation: function () {
				if (!this.orderInfo.store.latitude || !this.orderInfo.store.longitude)
					return this.$util.Tips({
						title: this.$t(`缺少经纬度信息无法查看地图`)
					});
				uni.openLocation({
					latitude: parseFloat(this.orderInfo.store.latitude),
					longitude: parseFloat(this.orderInfo.store.longitude),
					scale: 8,
					name: this.orderInfo.store.store_name,
					address: this.orderInfo.store.store_address,
					success: function () {}
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: $page-color-base;
		padding-bottom: 100rpx;
	}

	.ostatus {
		padding: 50rpx 30rpx;
		color: #ffffff;
		background: url(/static/public/images/bg_Bubbles.jpg) no-repeat;
		background-size: 100%;
	}

	.address-content {
		align-items: center;
		padding: 20rpx;
		display: flex;
		margin-top: 10rpx;
		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 30rpx;
			color: $font-color-dark;
		}

		.name {
			margin-right: 24rpx;
			font-weight: 600;
		}

		.address {
			margin-top: 10rpx;
			font-size: 26rpx;
			color: $font-color-light;
		}


	}

	.money-label {
		&::before {
			content: '￥';
			font-size: 24rpx;
		}
	}
	
	.goods_name {
		display: block;
		font-size: 28rpx;
		color: $font-color-dark;
		line-height: 45rpx;
		height: 90rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
	
	.yt-list {
		background: #fff;
	}

	.yt-listyt-list {
		margin: 20rpx;
	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 30rpx 20rpx;
		position: relative;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30rpx;
		}

		.cell-icon {
			height: 32rpx;
			width: 32rpx;
			font-size: 22rpx;
			color: #fff;
			text-align: center;
			line-height: 32rpx;
			background: #f85e52;
			border-radius: 4rpx;
			margin-right: 12rpx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}

		}

		.cell-more {
			align-self: center;
			font-size: 24rpx;
			color: $font-color-light;
			margin-left: 8rpx;
			margin-right: -10rpx;
		}

		.cell-tit {
			flex: 1;
			font-size: 28rpx;
			color: $font-color-dark;
			margin-right: 10rpx;
		}

		.cell-tip {
			font-size: 28rpx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color;
			}

			&.red {
				color: $font-color-red;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 90rpx;
			}
		}

		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}

	.offlineimg_item {
		image {
			flex-shrink: 0;
			width: 140rpx;
			height: 140rpx;
			border-radius: 4rpx;
			margin-right: 10rpx;
		}
	}

	.popup_box {
		padding: 0rpx 20rpx;

		.title {
			display: flex;
			height: 100rpx;
			align-items: center;
			font-weight: 700;
			font-size: 32rpx;
		}

		.input {
			padding: 20rpx;
		}
	}

	.action-box {
		width: 100%;
		background-color: #ffffff;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
	}
	.writeOff {
		background-color: #fff;
		margin-top: 5rpx;
		padding-bottom: 30rpx;
		.title {
			font-size: 30rpx;
			color: #282828;
			height: 87rpx;
			border-bottom: 1px solid #f0f0f0;
			padding: 0 30rpx;
			line-height: 87rpx;
		}
		.grayBg {
			background-color: #f2f5f7;
			width: 590rpx;
			height: 384rpx;
			border-radius: 20rpx 20rpx 0 0;
			margin: 50rpx auto 0 auto;
			padding-top: 55rpx;
			position: relative;
			.written {
				position: absolute;
				top: 0;
				right: 0;
				width: 130rpx;
				height: 130rpx;
				image {
					width: 100%;
					height: 100%;
				}
			}
			.pictrue {
				width: 290rpx;
				height: 290rpx;
				margin: 0 auto;
				image {
					width: 100%;
					height: 100%;
					display: block;
				}
			}
		}
		.gear {
			width: 590rpx;
			height: 30rpx;
			margin: 0 auto;
			image {
				width: 100%;
				height: 100%;
				display: block;
			}
		}
		.num {
			background-color: #f0c34c;
			width: 590rpx;
			height: 84rpx;
			color: #282828;
			font-size: 48rpx;
			margin: 0 auto;
			border-radius: 0 0 20rpx 20rpx;
			text-align: center;
			padding-top: 4rpx;
		}
		.rules {
			margin: 46rpx 30rpx 0 30rpx;
			border-top: 1px solid #f0f0f0;
			padding-top: 10rpx;
			.item {
				margin-top: 20rpx;
				.rulesTitle {
					font-size: 28rpx;
					color: #282828;
					.iconfont {
						font-size: 30rpx;
						color: #333;
						margin-right: 8rpx;
						margin-top: 5rpx;
					}
				}
				.info {
					font-size: 28rpx;
					color: #999;
					margin-top: 7rpx;
					.time {
						margin-left: 20rpx;
					}
				}
			}
		}
	}
	.map {
		height: 86rpx;
		font-size: 30rpx;
		color: #282828;
		line-height: 86rpx;
		border-bottom: 1px solid #f0f0f0;
		margin-top: 13rpx;
		background-color: #fff;
		padding: 0 30rpx;
		.place {
			font-size: 26rpx;
			// width: 176rpx;
			height: 50rpx;
			border-radius: 25rpx;
			line-height: 50rpx;
			text-align: center;
			padding: 0 10rpx;
			.iconfont {
				font-size: 27rpx;
				height: 27rpx;
				line-height: 27rpx;
				margin: 2rpx 3rpx 0 0;
			}
		}
	}
	.wrapper {
		background-color: #fff;
		margin-top: 12rpx;
		padding: 30rpx;
		.acea-row {
			display: flex;
			flex-wrap: nowrap;
		}
		.item {
			font-size: 28rpx;
			color: #282828;
			display: flex;
			justify-content: space-between;
			.conter {
				// color: #868686;
				width: 480srpx;
				display: flex;
				flex-wrap: nowrap;
				justify-content: flex-end;
				.copy {
					font-size: 20rpx;
					color: #333;
					border-radius: 3rpx;
					border: 1rpx solid #666;
					padding: 3rpx 15rpx;
					margin-left: 24rpx;
					white-space: nowrap;
				}
			}
		}
		.item ~ .item {
			margin-top: 20rpx;
			white-space: normal;
			word-break: break-all;
			word-wrap: break-word;
		}
		.actualPay {
			border-top: 1rpx solid #eee;
			margin-top: 30rpx;
			padding-top: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.pay-people {
				display: flex;
				align-items: center;
		
				image {
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
				}
		
				.pay-nickname {
					margin-right: 20rpx;
					padding: 0 10rpx;
				}
			}
			.money {
				font-weight: bold;
				font-size: 30rpx;
				color: #FF0000;
			}
		}
	}
	.hx-address {
		font-size: 26rpx;
		color: #868686;
		background-color: #fff;
		padding: 35rpx 30rpx;
		margin-bottom: 12rpx;
		display: flex;
		justify-content: space-between;
		.icon {
			.iconfont {
				width: 44rpx;
				height: 44rpx;
				background: var(--view-minorColorT);
				font-size: 20rpx;
				border-radius: 50%;
				text-align: center;
				line-height: 44rpx;
				color: var(--view-theme);
				margin-left: 26rpx;
			}
		}
		.name {
			font-size: 30rpx;
			color: #282828;
			margin-bottom: 15rpx;
			.store_phone {
				margin-left: 40rpx;
			}
		}
	}

</style>
